package com.onlineMIS.ORM.DAO.headQ.barCodeGentor;

import java.util.List;

import org.apache.taglibs.standard.lang.jstl.NullLiteral;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.onlineMIS.ORM.DAO.BaseDAO;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.Product;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.ProductIdentitySequence;

@Repository
public class ProductIdentitySequenceDaoImpl  extends BaseDAO<ProductIdentitySequence> {
		
	public ProductIdentitySequence getSequence(int year_ID, int quarter_ID, int category_level_ID, int category_ID) {

		DetachedCriteria criteria = DetachedCriteria.forClass(ProductIdentitySequence.class);
		
		criteria.add(Restrictions.eq("yearId", year_ID));	
		criteria.add(Restrictions.eq("quarterId", quarter_ID));			
		criteria.add(Restrictions.eq("categoryLevel1Id",category_level_ID));	
		criteria.add(Restrictions.eq("cateogryId", category_ID));	
		List<ProductIdentitySequence> list = this.getByCritera(criteria, true);
		if (list == null || list.size() == 0) {
			return null;
		}else {
			return list.get(0);
		}	
	}

	public void updateProductIS(int year_ID, int quarter_ID, int category_level_ID, int category_ID, int sequence) {
		ProductIdentitySequence pr = new ProductIdentitySequence();
		pr.setYearId(year_ID);
		pr.setQuarterId(quarter_ID);
		pr.setCategoryLevel1Id(category_level_ID);
		pr.setCateogryId(category_ID);
		pr.setSequence(sequence);
		update(pr, true);		
	}

	

}
